#ifndef _SMTPCLIENT_H_
#define _SMTPCLIENT_H_

#include <utillib/util/Mime.h>
#include <utillib/util/Event.h>

#define SMTP_PORT	25

#define	WM_SMTP_SENDPACKET		( WM_USER + 101 )

#define SMTP_PACKET_SIZE	8192

#define EMAIL_LENGTH		100
#define NICKNAME_LENGTH		100

#define	MAX_RECEIVER_USER	20

namespace util
{
	namespace util
	{
		class Mime;
	};
};

namespace netlib
{
	namespace net
	{
		class Mime;

		class SMTPClient
		{
		private:
			enum FTP_STATUS
			{
				SMTP_ERROR = -1,
				SMTP_CON = 0,
				SMTP_HELO,
				SMTP_MAILFROM,
				SMTP_RCPTTO,
				SMTP_DATA,
				SMTP_DONE,
				SMTP_FINISH,
				SMTP_AUTH_ID,
				SMTP_AUTH_PASSWORD,
				SMTP_AUTH_LOGIN,

			};

		public:
			SMTPClient();
			virtual ~SMTPClient();

			bool connect( const char *address, const u_short port , const char *id  , const char *password = NULL, HWND parentWnd = NULL );
			void close();

			bool setSender( const char *senderID , const char *nickname );
			bool setReceiver( const char *receiverID );
			bool setBody( const char *subject, const char *data );
			bool setFile( const char *attachFileName  );

			bool submit();
			void stopSend(){ m_mailStopEvent.set(); };
		protected:
			void initSocketEnv();
			void releaseSocketEnv();

			bool sendCommand( const char *buffer , size_t size );
			int parseSMTPMessage(int mode);

			char *m_serverAddress;
			u_short m_port;

			DWORD m_timeOut;

			void *lpCallbackGetFileParam;
			SOCKET m_connSocket;

			char m_senderID[ EMAIL_LENGTH ];
			char m_senderNickName[ NICKNAME_LENGTH ];
			char m_receiverID[ MAX_RECEIVER_USER ][ EMAIL_LENGTH ];

			int	m_receiverUserSize;
			BYTE m_attachFileCount;

			HWND m_parentWnd;

			utillib::util::Mime m_mime;
			utillib::util::Event m_mailStopEvent;
		};
	}
}

#endif